package com.ych.controller;

import com.ych.beans.Message;
import com.ych.beans.UserManager;
import com.ych.service.UserService;
import com.ych.util.logUtil.AddLog;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpSession;

@RestController
@RequestMapping("/sys")
public class UserController {
    @Autowired
    UserService service;

    @AddLog
    @GetMapping({"/user","/user/{userId}"})
    public Message selectUser(@RequestParam(required = false) Integer pageNo, @RequestParam(required = false) String key, @PathVariable(required = false) Integer userId){
        return service.selectUser(pageNo,key,userId);
    }

    @AddLog
    @PostMapping("/user")
    public Message addUser(@RequestBody UserManager r){
        return service.addUser(r);
    }

    @AddLog
    @DeleteMapping("/user/{userId}")
    public Message deleteUser(@PathVariable Integer userId){
        return service.deleteUser(userId);
    }

    @PostMapping("/login")
    public Message login(@RequestBody UserManager userManager, HttpSession session){
        return service.login(userManager,session);
    }
}
